|
STEP 8: Cool File of the Day
|
As a completely different angle on the dynamic selecion of music content, suppose we wanted a Web page to be appear as though it were being updated regularly, but not in a completely random fashion. With a little help from JavaScript's built in Date object we can make it appear as though a Web site's music is being updated on a daily basis. When a Web page uses this kind of music updating scheme, all visitors to the page will hear the same music play on any given date of the year.
The page for this step of the tutorial is using just such a scheme, and the music file that is now playing through the player instance below will play for all people who view this page on this date of the year. Try reloading this page several times. Every time you reload the page you should still hear the same file play, unless you're up really late burning the midnight oil and the date rolls over as you reloaded the page.
Now let's take a look at the source code for this example...
| |
<SCRIPT SRC="music-object.js"></SCRIPT> <SCRIPT LANGUAGE=JavaScript><!-- // musicFiles = new Array ( 'ambient.rmf', 'classical.rmf', 'house.rmf', 'jungle.rmf', 'lounge.rmf', 'modern-rock.rmf', 'sfx-medley.rmf', 'techno.rmf', 'trance.rmf' ); var today = new Date (), msPerDay= 24 * 60 * 60 * 1000, currentSelection = (Math.round (today.getTime () / msPerDay) % musicFiles.length), fileOfTheDay = musicFiles [currentSelection] ; Music.magicEmbed ('SRC="' + fileOfTheDay + '" WIDTH=144 HEIGHT=60 DISPLAY=SONG AUTOSTART=TRUE'); |
In the sample code listing above, the highlighted code indicates the code that should be customized to suit the needs of your specific application. The contents of the musicFiles array can be customized to accommodate all the files you'd like to step through on a daily basis. This array may contain as many file URLs as you like and the code will automatically cycle through this list, each day selecting the next file from the list. Each element of the array is a string, representing the URL of a file. You should only include URLs for files that can be supported by the player (see the appendix Beatnik Player Supported File Types).
In this example we're displaying the control panel, but if you wanted the control panel to be hidden you could simply replace the
So, rather than having the following somewhat inefficient code...
<SCRIPT SRC="music-object.js"></SCRIPT> <SCRIPT LANGUAGE=JavaScript><!-- // musicFiles = new Array ( 'media/music/rmf/jack-of-all-trades.rmf', 'media/music/rmf/little-munchkins-of-aberdeen.rmf', 'media/music/rmf/attack-of-the-manic-triads.rmf', 'media/music/rmf/under-the-missile-toe.rmf', 'media/music/rmf/calm-yeah-right.rmf', 'media/music/rmf/expert-flavors-of-trance.rmf', 'media/music/rmf/a-cinch.rmf', 'media/music/rmf/experiments-on-espresso.rmf', 'media/music/rmf/mid-day-crisis.rmf', 'media/music/rmf/executive-management-boogaloo.rmf', 'media/music/rmf/downside-of-an-upswing.rmf', 'media/music/rmf/meet-the-light-of-day.rmf', ); var today = new Date (), msPerDay= 24 * 60 * 60 * 1000, currentSelection = (Math.round (today.getTime () / msPerDay) % musicFiles.length), fileOfTheDay = musicFiles [currentSelection] ; Music.magicEmbed ('SRC="' + fileOfTheDay + '" WIDTH=0 HEIGHT=0 HIDDEN AUTOSTART=TRUE'); |
...you could instead place the common file URL path media/music/rmf/ in the call to the magicEmbed method, as follows...
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT LANGUAGE=JavaScript><!-- //
musicFiles = new Array (
'jack-of-all-trades.rmf',
'little-munchkins-of-aberdeen.rmf',
'attack-of-the-manic-triads.rmf',
'under-the-missile-toe.rmf',
'calm-yeah-right.rmf',
'expert-flavors-of-trance.rmf',
'a-cinch.rmf',
'experiments-on-espresso.rmf',
'mid-day-crisis.rmf',
'executive-management-boogaloo.rmf',
'downside-of-an-upswing.rmf',
'meet-the-light-of-day.rmf',
);
var
today = new Date (),
msPerDay= 24 * 60 * 60 * 1000,
currentSelection = (Math.round (today.getTime () / msPerDay) % musicFiles.length),
fileOfTheDay = musicFiles [currentSelection]
;
Music.magicEmbed ('SRC="media/music/rmf/' + fileOfTheDay + '" WIDTH=0 HEIGHT=0 HIDDEN AUTOSTART=TRUE');
|